package com.huawei.esdk.tp.device.smc.v100r003c00.convert;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.platform.common.exception.SDKException;
import com.huawei.esdk.platform.common.utils.DateUtils;
import com.huawei.esdk.platform.common.utils.StringUtils;
import com.huawei.esdk.tp.common.ErrInfo;
import com.huawei.esdk.tp.cxf.enumgen.ConfSiteStatusMapping;
import com.huawei.esdk.tp.cxf.enumgen.DayOfWeekMapping;
import com.huawei.esdk.tp.domain.model.Conference;
import com.huawei.esdk.tp.domain.model.PeriodicalConference;
import com.huawei.esdk.tp.domain.model.ScheduleConference;
import com.huawei.esdk.tp.domain.model.Site;
import com.huawei.esdk.tp.domain.model.SiteInConference;
import com.huawei.esdk.tp.domain.model.bean.ErrorInfo;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r002c01.MediaEncryptType;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r002c01.MediaEncryptTypeMapping;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r002c01.PresentationType;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r002c01.PresentationTypeMapping;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.AddSiteInScheduledConf;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.AddSiteInScheduledConfResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ArrayOfDayOfWeek;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.EditFutureConf;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.EditFutureConfResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.AccessCode;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ArrayOfScheduleSiteParam2;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.DialMode;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.RecurrenceInfo;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.RecurrenceRange;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ScheduleConf;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ScheduleConfResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ScheduleSiteParam2;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ScheduleTime;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ScheduledConfInfo;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ScheduledConfParamEx2;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.SiteFrom;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.SiteType;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.SmcErr2;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.TimeSpanEx;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.VideoFormat;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.VideoParam;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.VideoProtocol;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ArrayOfConferenceId;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ArrayOfString;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ConfSiteStatus;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ConferenceId;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ConferenceStatus;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.QueryConfSitesStatus;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.QueryConfSitesStatusResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.QueryConferencesStatus;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.QueryConferencesStatusResponse;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.SiteStatus;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.SiteVolume;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.DayOfWeek;
import com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.RecurrenceFrequency;

public class TPSMC20V1R3C00ConfMgrConvert
{
    public List<SiteVolume> siteVolumeExModel2Soap(List<com.huawei.esdk.tp.domain.model.bean.SiteVolume> siteVolumeExs)
    {
        List<SiteVolume> siteVolumes = new ArrayList<SiteVolume>();
        for (com.huawei.esdk.tp.domain.model.bean.SiteVolume siteVolumeEx : siteVolumeExs)
        {
            if (null != siteVolumeEx)
            {
                siteVolumes.add(siteVolumeExModel2Soap(siteVolumeEx));
            }
        }
        return siteVolumes;
    }
    
    public SiteVolume siteVolumeExModel2Soap(com.huawei.esdk.tp.domain.model.bean.SiteVolume siteVolumeEx)
    {
        SiteVolume siteVolume = new SiteVolume();
        siteVolume.setSiteUri(siteVolumeEx.getSiteUri());
        siteVolume.setVolume(siteVolumeEx.getVolume());
        return siteVolume;
    }
    
    public QueryConfSitesStatus queryConfSitesStatusModel2Soap(String confId, List<String> siteUris)
    {
        // 定义协议相关的Bean
        QueryConfSitesStatus reqBean = new QueryConfSitesStatus();
        
        // 会议ID
        ConferenceId conferenceId = new ConferenceId();
        
        conferenceId.setConfInternalId(Long.parseLong(confId));
        reqBean.setConfId(conferenceId);
        
        ArrayOfString arrayOfString = new ArrayOfString();
        /*
         * DTS单号: DTS2013042605527 会场uri为空 查询出所有
         */
        if (null == siteUris)
        {
            reqBean.setSiteUris(arrayOfString);
            return reqBean;
        }
        
        if (1 == siteUris.size())
        {
            if ("".equals(siteUris.get(0)))
            {
                reqBean.setSiteUris(arrayOfString);
            }
            else
            {
                arrayOfString.getString().add(siteUris.get(0));
                reqBean.setSiteUris(arrayOfString);
            }
        }
        else
        {
            for (int i = 0; i < siteUris.size(); i++)
            {
                arrayOfString.getString().add(siteUris.get(i));
            }
            reqBean.setSiteUris(arrayOfString);
        }
        return reqBean;
    }
    
    public SDKResult<List<Conference>> queryConferencesStatusResponseSouth2SDKResult(
        QueryConferencesStatusResponse response)
    {
        SDKResult<List<Conference>> result = new SDKResult<List<Conference>>();
        result.setErrCode(response.getQueryConferencesStatusResult().getErrCode());
        result.setDescription(response.getQueryConferencesStatusResult().getDescription());
        result.setSubSystem(String.valueOf(response.getQueryConferencesStatusResult().getSubSystem()));
        
        List<Conference> list = new LinkedList<Conference>();
        Conference conf = null;
        if (null != response.getConfsStatus() && response.getConfsStatus().getConferenceStatus().size() > 0)
        {
            for (int i = 0; i < response.getConfsStatus().getConferenceStatus().size(); i++)
            {
                ConferenceStatus conferenceStatus = response.getConfsStatus().getConferenceStatus().get(i);
                conf = new Conference(conferenceStatus.getId().getConfInternalId().toString());
                conf.setName(conferenceStatus.getName());
                conf.setStatus(com.huawei.esdk.tp.domain.model.bean.ConfStatus.valueOf(conferenceStatus.getStatus()
                    .toString()));
                com.huawei.esdk.tp.domain.model.ConferenceStatus confStatus =
                    new com.huawei.esdk.tp.domain.model.ConferenceStatus();
                confStatus.setBroadcast(conferenceStatus.getBroadcast());
                confStatus.setChair(conferenceStatus.getChair());
                confStatus.setId(conferenceStatus.getId().getConfInternalId().toString());
                confStatus.setName(conferenceStatus.getName());
                confStatus.setSpeaking(conferenceStatus.getSpeaking());
                confStatus.setStatus(conferenceStatus.getStatus().toString());
                confStatus.setIsLock(conferenceStatus.isIsLock() ? 1 : 0);
                if (null != conferenceStatus.getAudioSwitchParam())
                {
                    confStatus.setSwtichGate((int)conferenceStatus.getAudioSwitchParam().getSwitchGate());
                }
                confStatus.setIsAudioSwitch(conferenceStatus.isIsAudioSwitch() ? 1 : 0);
                confStatus.setPresentation(conferenceStatus.getPresentation());
                
                //C30新增
                confStatus.setBeginTime(DateUtils.toDate(conferenceStatus.getBeginTime()));
                confStatus.setEndTime(DateUtils.toDate(conferenceStatus.getEndTime()));
                
                // DTS2015012910778，缺少节点isLockPresentation、lockPresentation
                confStatus.setLockPresentation(conferenceStatus.getLockPresentation());
                confStatus.setIsLockPresentation(conferenceStatus.isIsLockPresentation() ? 1 : 0);
                // end
                
                conf.setConferenceStatus(confStatus);
                list.add(conf);
            }
        }
        
        result.setResult(list);
        return result;
    }
    
    public SDKResult<List<SiteInConference>> queryConfSiteStatusSoap2model(QueryConfSitesStatusResponse res)
    {
        
        SDKResult<List<SiteInConference>> result = new SDKResult<List<SiteInConference>>();
        
        int resultCode = -1;
        // 南向发送soap消息，产品返回soap消息
        resultCode = (int)res.getQueryConfSitesStatusResult().getErrCode();
        // 南向发送soap消息，产品返回soap消息
        if (resultCode == 0)
        {
            SiteInConference confSiteStatusMap = null;
            List<SiteInConference> sites = new ArrayList<SiteInConference>();
            List<SiteStatus> southArrayOfSiteStatus = res.getSitesStatus().getSiteStatus();
            // 会场列表，可以有多个会场（当一个会场添加了N次的时候，该会场会显示1次）
            for (int j = 0; j < southArrayOfSiteStatus.size(); j++)
            {
                SiteStatus siteStatusSouth = southArrayOfSiteStatus.get(j);
                
                confSiteStatusMap = new SiteInConference();
                confSiteStatusMap.setUri(siteStatusSouth.getUri());
                
                ConfSiteStatus sonfSiteStatusSouth = southArrayOfSiteStatus.get(j).getStatus();
                
                //C30适配
                if (null != sonfSiteStatusSouth)
                {
                    confSiteStatusMap.setStatus(ConfSiteStatusMapping.enum2Int(com.huawei.esdk.tp.cxf.enumgen.ConfSiteStatus.valueOf(sonfSiteStatusSouth.toString())));
                }
                // 行业接口对外开放的ConfSiteStatus类型中，不包含Noexist,如果SMC返回的是Noexist的情况，视为Unknow
                confSiteStatusMap.setName(siteStatusSouth.getName());
                confSiteStatusMap.setSiteType(siteStatusSouth.getType().toString());
                confSiteStatusMap.setVideoSource(siteStatusSouth.getVideoSource());
                confSiteStatusMap.setVolume(siteStatusSouth.getVolume());
                if (siteStatusSouth.isIsQuiet())
                {
                    confSiteStatusMap.setIsQuiet(1);
                }
                else
                {
                    confSiteStatusMap.setIsQuiet(0);
                }
                if (siteStatusSouth.isIsMute())
                {
                    confSiteStatusMap.setIsMute(1);
                }
                else
                {
                    confSiteStatusMap.setIsMute(0);
                }
                
                // add by cWX191990, 查询不存在会场，返回该大Boolean可能为空，导致空指针异常
                if (null != siteStatusSouth.isIsLocalVideoOpen())
                {
                    //C30新增
                    confSiteStatusMap.setIsLocalVideoOpen(true == siteStatusSouth.isIsLocalVideoOpen() ? 1 : 0);
                }
                
                SmcErr2 errIndoSouth = siteStatusSouth.getCallFailedReson();
                if (null != errIndoSouth)
                {
                    ErrorInfo errInfoModal = new ErrorInfo();
                    errInfoModal.setErrCode(errIndoSouth.getErrCode());
                    errInfoModal.setDiscription(errIndoSouth.getDescription());
                    confSiteStatusMap.setCallFailedReason(errInfoModal);
                }
                
                // DTS2015012910778，缺少新增节点participantType、screens
                // DTS2015022803348，当会场不存在时，调用该接口返回2130000010空指针错误
                if (null != siteStatusSouth.getParticipantType())
                {
                    confSiteStatusMap.setParticipantType(siteStatusSouth.getParticipantType().toString());
                }
                confSiteStatusMap.setScreens(siteStatusSouth.getScreens());
                // end
                
                sites.add(confSiteStatusMap);
            }
            result.setResult(sites);
        }
        result.setErrCode(res.getQueryConfSitesStatusResult().getErrCode());
        
        return result;
    }
    
    /**
     * 查询会议状态，领域bean转南向bean * @param confIds /** * @return
     */
    public QueryConferencesStatus list2QueryConferencesStatusSouth(List<String> confIds)
    {
        QueryConferencesStatus queryConferencesStatusSouth = new QueryConferencesStatus();
        ArrayOfConferenceId arrayOfConferenceIdSouth = new ArrayOfConferenceId();
        ConferenceId conferenceId = null;
        for (int i = 0; i < confIds.size(); i++)
        {
            conferenceId = new ConferenceId();
            conferenceId.setConfInternalId(Long.parseLong(confIds.get(i)));
            arrayOfConferenceIdSouth.getConferenceId().add(conferenceId);
        }
        
        queryConferencesStatusSouth.setConfIds(arrayOfConferenceIdSouth);
        return queryConferencesStatusSouth;
    }
    
    public ScheduleConf scheduleConfModel2soap(ScheduleConference conf)
        throws SDKException
    {
        ScheduleConf scheduleConf = new ScheduleConf();
        
        ScheduledConfParamEx2 scheduledConfParamEx2South = new ScheduledConfParamEx2();
        ConferenceId conferenceId = new ConferenceId();
        Long confId = 0l;
        if (!StringUtils.isEmpty(conf.getId()))
        {
            confId = Long.parseLong(conf.getId());
        }
        conferenceId.setConfInternalId(confId);
        scheduledConfParamEx2South.setId(conferenceId);
        scheduledConfParamEx2South.setName(conf.getName());
        scheduledConfParamEx2South.setAccessCode(conf.getAccessCode());
        
        ScheduleTime scheduleTimeSouth = new ScheduleTime();
        // conftime-BeginTime
        if (null != conf.getBeginTime())
        {
            scheduleTimeSouth.setBeginTime(DateUtils.setTimezoneToUTC(DateUtils.toGregorianCalendarDate(conf.getBeginTime()),
                0));
        }
        TimeSpanEx timeSpanExSouth = new TimeSpanEx();
        // conftime-Duration
        timeSpanExSouth.setTimeSpan("PT" + conf.getLength() + "M");
        scheduleTimeSouth.setDuration(timeSpanExSouth);
        // conftime-Recurrence-周期性会议的情况，不考虑
        scheduledConfParamEx2South.setConfTime(scheduleTimeSouth);
        // 速率rate放在ScheduleConference中
        scheduledConfParamEx2South.setRate(conf.getRate());
        scheduledConfParamEx2South.setBillCode(conf.getBillCode());
        scheduledConfParamEx2South.setPassword(conf.getPassword());
        
        //C30新增
        scheduledConfParamEx2South.setChairmanPassword(conf.getChairmanPassword());
        
        VideoParam videoParamSouth = new VideoParam();
        
        videoParamSouth.setFormat(getVideoFormatInt2Enum(conf.getAuxVideoFormat()));
        
        videoParamSouth.setProtocol(getVideoProtocolInt2Enum(conf.getAuxVideoProtocol()));
        
        if (null == videoParamSouth.getFormat() && null == videoParamSouth.getProtocol())
        {
            scheduledConfParamEx2South.setPresentationVideo(null);
        }
        else
        {
            scheduledConfParamEx2South.setPresentationVideo(videoParamSouth);
        }
        
        //cpResource是int类型，需要判断是否为null
        if (null != conf.getCpResouce())
        {
            scheduledConfParamEx2South.setCPResource(conf.getCpResouce());
        }
        
        //C30适配
        MediaEncryptType mediaEncryTypeParam = MediaEncryptTypeMapping.int2Enum(conf.getMediaEncryptType());
        if (null != mediaEncryTypeParam)
        {
            scheduledConfParamEx2South.setMediaEncryptType(com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.MediaEncryptType.valueOf(mediaEncryTypeParam.toString()));
        }
        
        PresentationType presentationTypeParam = PresentationTypeMapping.int2Enum(conf.getPresentation());
        if (null != presentationTypeParam)
        {
            scheduledConfParamEx2South.setPresentation(com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.PresentationType.valueOf(presentationTypeParam.toString()));
        }
        
        if (null != conf.getIsLiveBroadcast())
        {
            scheduledConfParamEx2South.setIsLiveBroadcast(0 == conf.getIsLiveBroadcast() ? false : true);
        }
        if (null != conf.getIsRecording())
        {
            scheduledConfParamEx2South.setIsRecording(0 == conf.getIsRecording() ? false : true);
        }
        
        scheduleConf.setNewConf(scheduledConfParamEx2South);
        
        //会场转换
        ArrayOfScheduleSiteParam2 arrayOfScheduleSiteParam2South = new ArrayOfScheduleSiteParam2();
        ScheduleSiteParam2 scheduleSiteParam2South = null;
        List<SiteInConference> siteInConferences = conf.getSites();
        
        // 会议中的会场数据
        for (SiteInConference siteInConference : siteInConferences)
        {
            if (null != siteInConference)
            {
                scheduleSiteParam2South = siteCommModel2soap(siteInConference);
                arrayOfScheduleSiteParam2South.getScheduleSiteParam2().add(scheduleSiteParam2South);
            }
        }
        
        scheduleConf.setSites(arrayOfScheduleSiteParam2South);
        
        // conftime-Recurrence-周期性会议情况下的特殊情况
        if (PeriodicalConference.class.isInstance(conf))
        {
            
            PeriodicalConference srcConf = (PeriodicalConference)conf;
            
            if (null != srcConf.getInterval() && !StringUtils.isEmpty(srcConf.getFrequency()))
            {
                RecurrenceInfo recurrenceInfoSouth = new RecurrenceInfo();
                
                recurrenceInfoSouth.setFrequency(RecurrenceFrequency.valueOf(srcConf.getFrequency()));
                
                recurrenceInfoSouth.setInterval(srcConf.getInterval());
                
                ArrayOfDayOfWeek arrayOfDayOfWeekSouth = null;
                List<Integer> dayList = srcConf.getWeekDays();
                
                if (null != dayList && !dayList.isEmpty())
                {
                    arrayOfDayOfWeekSouth = new ArrayOfDayOfWeek();
                    for (Integer day : dayList)
                    {
                        if (null != DayOfWeekMapping.int2Enum(day))
                        {
                            arrayOfDayOfWeekSouth.getDayOfWeek().add(DayOfWeek.valueOf(DayOfWeekMapping.int2Enum(day)
                                .toString()));
                        }
                    }
                }
                
                recurrenceInfoSouth.setWeekDays(arrayOfDayOfWeekSouth);
                if (null != srcConf.getMonthDay())
                {
                    recurrenceInfoSouth.setMonthDay(srcConf.getMonthDay());
                }
                if (null != srcConf.getWeekDay())
                {
                    recurrenceInfoSouth.setWeekDay(srcConf.getWeekDay());
                }
                // month是月的信息，不考虑年的情况该字段不用填写
                RecurrenceRange recurrenceRangeSouth = null;
                if (null != srcConf.getCount())
                {
                    recurrenceRangeSouth = new RecurrenceRange();
                    recurrenceRangeSouth.setCount(srcConf.getCount());
                }
                if (null != srcConf.getEndDate() && null != recurrenceRangeSouth)
                {
                    recurrenceRangeSouth.setUntilDate(DateUtils.setTimezoneToUTC(DateUtils.toGregorianCalendarDate(srcConf.getEndDate()),
                        0));
                }
                recurrenceInfoSouth.setRange(recurrenceRangeSouth);
                scheduleTimeSouth.setRecurrence(recurrenceInfoSouth);
            }
            // ///////////////////////周期会议特性/////////////
            
        }
        return scheduleConf;
    }
    
    public Object scheduleConfSoap2model(ScheduleConfResponse responseSouth)
    {
        SDKResult<PeriodicalConference> result = new SDKResult<PeriodicalConference>();
        long errorCode = responseSouth.getScheduleConfResult().getErrCode();
        result.setErrCode(responseSouth.getScheduleConfResult().getErrCode());
        
        if (0 != errorCode)
        {
            return result;
        }
        PeriodicalConference desMsg = new PeriodicalConference();
        
        setConferenceEx(responseSouth, desMsg);
        result.setResult(desMsg);
        
        return result;
    }
    
    /**
     * 修改周期会议的bean的convert方法和预约会议的类似 修改会议，南向领域bean转南向soap bean 用于向SMC产品发消息的情况
     * response model2soap
     * @throws SDKException 
     */
    public EditFutureConf editScheduleConfModel2soap(ScheduleConference srcConf)
        throws SDKException
    {
        
        ScheduleConf scheduleConfSouth = scheduleConfModel2soap(srcConf);
        
        EditFutureConf editFutureConfSouth = new EditFutureConf();
        editFutureConfSouth.setEditConf(scheduleConfSouth.getNewConf());
        editFutureConfSouth.setSites(scheduleConfSouth.getSites());
        
        if (PeriodicalConference.class.isInstance(srcConf))
        {
            PeriodicalConference priodonf = (PeriodicalConference)srcConf;
            if (null != priodonf.getSubConfStartTime())
            {
                editFutureConfSouth.setBeginTime(DateUtils.setTimezoneToUTC(DateUtils.toGregorianCalendarDate(priodonf.getSubConfStartTime()),
                    0));
            }
        }
        
        return editFutureConfSouth;
    }
    
    /**
     * 预约会议，南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    public Object editScheduleConfSoap2model(EditFutureConfResponse resMsg)
    {
        
        ScheduleConfResponse scheduleConfResponseSouth = new ScheduleConfResponse();
        scheduleConfResponseSouth.setConfs(resMsg.getConfs());
        scheduleConfResponseSouth.setScheduleConfResult(resMsg.getEditFutureConfResult());
        
        return scheduleConfSoap2model(scheduleConfResponseSouth);
    }
    
    public AddSiteInScheduledConf addSiteToScheduledConfModel2SouthSoap(ScheduleConference conference, Site site,
        Date beginTime, boolean useAnonymousSite)
        throws SDKException
    {
        // 领域Bean转成南向SOAP Bean
        AddSiteInScheduledConf southRequest = new AddSiteInScheduledConf();
        ConferenceId conferenceId = new ConferenceId();
        ScheduleSiteParam2 siteParam = new ScheduleSiteParam2();
        
        conferenceId.setConfInternalId(Long.parseLong(conference.getId()));
        southRequest.setConfId(conferenceId);
        
        siteParam.setName(site.getName());
        if (!StringUtils.isEmpty(site.getSiteType()))
        {
            siteParam.setType(SiteType.valueOf(site.getSiteType()));
        }
        siteParam.setDialingMode(StringUtils.isEmpty(site.getDialingMode()) ? null
            : DialMode.valueOf(site.getDialingMode()));
        siteParam.setUri(site.getUri());
        siteParam.setRate(site.getRate());
        siteParam.setFrom(StringUtils.isEmpty(site.getFrom()) ? null : SiteFrom.valueOf(site.getFrom()));
        VideoParam videoParamSouth = new VideoParam();
        videoParamSouth.setFormat(getVideoFormatInt2Enum(site.getVideoFormat()));
        videoParamSouth.setProtocol(getVideoProtocolInt2Enum(site.getVideoProtocol()));
        siteParam.setVideo(videoParamSouth);
        
        // R5C00新增
        if (!StringUtils.isEmpty(site.getParticipantType()))
        {
            siteParam.setParticipantType(com.huawei.esdk.tp.southcommu.cxf.gen.v100r003c00.ParticipantType.valueOf(site.getParticipantType()));
        }
        
        if (null != site.getIsLockVideoSource())
        {
            siteParam.setIsLockVideoSource(0 == site.getIsLockVideoSource() ? false : true);
        }
        // R5C00 end
        
        southRequest.setSiteParam(siteParam);
        southRequest.setBeginTime(DateUtils.setTimezoneToUTC(DateUtils.toGregorianCalendarDate(beginTime), 0));
        southRequest.setIsUseAnonymousSite(useAnonymousSite);
        
        return southRequest;
    }
    
    public SDKResult<ScheduleConference> addSiteToScheduledConfSouthSoap2Model(ScheduleConference conference,
        Site site, AddSiteInScheduledConfResponse southResponse)
    {
        // 将SMC返回的南向SOAP Bean转成领域Bean
        SDKResult<ScheduleConference> modelBean = new SDKResult<ScheduleConference>();
        
        if (null == southResponse)
        {
            modelBean.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
            return modelBean;
        }
        
        // 1.设置错误码
        modelBean.setErrCode(southResponse.getAddSiteInScheduledConfResult().getErrCode());
        
        // 2.将南向SMC SOAP
        // Bean中的AccessCode对象属性设置到领域模型Conference终的SiteInConference中
        if (null != southResponse.getConfs())
        {
            List<AccessCode> accessCodeSouths = new ArrayList<AccessCode>();
            for (int i = 0; i < southResponse.getConfs().getScheduledConfInfo().size(); i++)
            {
                accessCodeSouths.addAll(southResponse.getConfs()
                    .getScheduledConfInfo()
                    .get(i)
                    .getAccessCode()
                    .getAccessCode());
            }
            
            List<SiteInConference> siteInConferences = new ArrayList<SiteInConference>();
            AccessCode accessCodeSouth = null;
            SiteInConference siteInConference = null;
            for (int i = 0; i < accessCodeSouths.size(); i++)
            {
                accessCodeSouth = accessCodeSouths.get(i);
                siteInConference = new SiteInConference(conference.getId(), site.getUri());
                
                siteInConference.setConfAccessCode(accessCodeSouth.getConfAccessCode());
                siteInConference.setName(accessCodeSouth.getSiteName());
                siteInConference.setUri(accessCodeSouth.getSiteUri());
                siteInConference.setBeginTime(accessCodeSouth.getBeginTime().toGregorianCalendar().getTime());
                siteInConference.setMcuUri(accessCodeSouth.getMCUUri());
                
                siteInConferences.add(siteInConference);
            }
            conference.setSites(siteInConferences);
            modelBean.setResult(conference);
        }
        
        return modelBean;
    }
    
    /**
     * 会场信息转换 转换时按照对象的粒度转换 南向领域bean转南向soap bean 用于向SMC产品发消息的情况 response
     * model2soap
     * @throws SDKException 
     */
    private ScheduleSiteParam2 siteCommModel2soap(SiteInConference siteInConference)
        throws SDKException
    {
        ScheduleSiteParam2 scheduleSiteParam2South = new ScheduleSiteParam2();
        scheduleSiteParam2South.setUri(siteInConference.getUri());
        scheduleSiteParam2South.setName(siteInConference.getName());
        
        if (!StringUtils.isEmpty(siteInConference.getSiteType()))
        {
            scheduleSiteParam2South.setType(SiteType.valueOf(siteInConference.getSiteType()));
        }
        if (!StringUtils.isEmpty(siteInConference.getFrom()))
        {
            scheduleSiteParam2South.setFrom(SiteFrom.valueOf(siteInConference.getFrom()));
        }
        if (!StringUtils.isEmpty(siteInConference.getDialingMode()))
        {
            scheduleSiteParam2South.setDialingMode(DialMode.valueOf(siteInConference.getDialingMode()));
        }
        scheduleSiteParam2South.setRate(siteInConference.getRate());
        
        VideoParam videoParamSouth = new VideoParam();
        
        videoParamSouth.setFormat(getVideoFormatInt2Enum(siteInConference.getVideoFormat()));
        
        videoParamSouth.setProtocol(getVideoProtocolInt2Enum(siteInConference.getVideoProtocol()));
        
        if (null == videoParamSouth.getProtocol() && null == videoParamSouth.getFormat())
        {
            scheduleSiteParam2South.setVideo(null);
        }
        else
        {
            scheduleSiteParam2South.setVideo(videoParamSouth);
        }
        
        return scheduleSiteParam2South;
    }
    
    /**
     * 预约会议 南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    private void setConferenceEx(ScheduleConfResponse resMsg, PeriodicalConference desMsg)
    {
        ScheduledConfInfo scheduledConfInfoSouth = resMsg.getConfs().getScheduledConfInfo().get(0);
        desMsg.setId(scheduledConfInfoSouth.getId().getConfInternalId().toString());
        List<AccessCode> arrayOfAccessCodeSouth = scheduledConfInfoSouth.getAccessCode().getAccessCode();
        List<SiteInConference> siteInConferences = new ArrayList<SiteInConference>();
        SiteInConference siteInConference = null;
        for (AccessCode accessCodeSouth : arrayOfAccessCodeSouth)
        {
            siteInConference = siteCommSoap2model(accessCodeSouth);
            siteInConferences.add(siteInConference);
        }
        desMsg.setSites(siteInConferences);
        
        //Add in R3
        desMsg.setRecorderAddr(scheduledConfInfoSouth.getRecorderAddr());
    }
    
    /**
     * 预约会议中会场信息的转换 南向soapbean转南向领域bean 用于返回值的情况 ModelBean
     * soap2model(SoapBean){}
     */
    private SiteInConference siteCommSoap2model(AccessCode accessCodeSouth)
    {
        
        SiteInConference siteInConference = new SiteInConference();
        siteInConference.setUri(accessCodeSouth.getSiteUri());
        siteInConference.setName(accessCodeSouth.getSiteName());
        siteInConference.setAccessCode(accessCodeSouth.getConfAccessCode());
        siteInConference.setBeginTime(DateUtils.toDate(accessCodeSouth.getBeginTime()));
        
        return siteInConference;
    }
    
    private VideoFormat getVideoFormatInt2Enum(Integer num)
        throws SDKException
    {
        final int AUTO = 0;
        final int CIF_4 = 1;
        final int P_720 = 2;
        final int P_1080 = 3;
        final int P_480 = 4;
        final int P_720_60_F = 5;
        final int P_1080_60_F = 6;
        final int Q_CIF = 7;
        final int CIF = 8;
        final int SQ_CIF = 9;
        final int CIF_2 = 10;
        final int I_108 = 11;
        final int I_480 = 12;
        
        final int MIN = 0;
        final int MAX = 12;
        
        if (null == num)
        {
            return VideoFormat.AUTO;
        }
        
        if (num < MIN || num > MAX)
        {
            SDKException sdkException = new SDKException(ErrInfo.DATA_ERRORDESC);
            sdkException.setSdkErrCode(ErrInfo.DATA_ERRORCODE);
            throw sdkException;
        }
        
        switch (num)
        {
            case AUTO:
            {
                return VideoFormat.AUTO;
            }
            case CIF_4:
            {
                return VideoFormat.CIF_4;
            }
            case P_720:
            {
                return VideoFormat.P_720;
            }
            case P_1080:
            {
                return VideoFormat.P_1080;
            }
            case P_480:
            {
                return VideoFormat.P_480;
            }
            case P_720_60_F:
            {
                return VideoFormat.P_720_60_F;
            }
            case P_1080_60_F:
            {
                return VideoFormat.P_1080_60_F;
            }
            case Q_CIF:
            {
                return VideoFormat.Q_CIF;
            }
            case CIF:
            {
                return VideoFormat.CIF;
            }
            case SQ_CIF:
            {
                return VideoFormat.SQ_CIF;
            }
            case CIF_2:
            {
                return VideoFormat.CIF_2;
            }
            case I_108:
            {
                return VideoFormat.I_108;
            }
            case I_480:
            {
                return VideoFormat.I_480;
            }
                
            default:
            {
                return null;
            }
        }
    }
    
    private VideoProtocol getVideoProtocolInt2Enum(Integer num)
        throws SDKException
    {
        final int AUTO = 0;
        final int H_261 = 1;
        final int H_263 = 2;
        final int H_264 = 3;
        final int MIN = 0;
        final int MAX = 3;
        
        if (null == num)
        {
            return VideoProtocol.AUTO;
        }
        
        if (num < MIN || num > MAX)
        {
            SDKException sdkException = new SDKException(ErrInfo.DATA_ERRORDESC);
            sdkException.setSdkErrCode(ErrInfo.DATA_ERRORCODE);
            throw sdkException;
        }
        
        switch (num)
        {
            case AUTO:
            {
                return VideoProtocol.AUTO;
            }
            case H_261:
            {
                return VideoProtocol.H_261;
            }
            case H_263:
            {
                return VideoProtocol.H_263;
            }
            case H_264:
            {
                return VideoProtocol.H_264;
            }
            default:
            {
                return null;
            }
        }
    }
}
